﻿/*
 * ============ [ 废土 ] ============
 *
 * [ 维护者 ]  argoran@gmail.com
 * [  状态  ]  原型
 *
 * ============ [ 注释 ] ============
 *
 * 处理14号消息的类
 *
 * ==================================
 */

using System;

using LastLand.Data.Global;

using Up2Link.SegString;
using Up2Link.Server;

namespace LastLand.Core.MsgProcessor
{
    public class CMsgLogout : IMessageProcessor
    {
        public void ProcessMessage(CMessagePack<CMessageSS> _msgPack)
        {
            Int32 index = _msgPack.index;

            if (CData.connections[index].IsLoggedIn())
            {
                CData.userAccounts[CData.connections[index].Account].ConnectionBinding = -1;
                CData.connections[index].Status = CConst.USER_STATUS_CONNECTED;
                CData.connections[index].Account = null;
                CMessageSS okLogoutMsg = new CMessageSS(CConst.SERVER_MESSAGE_COMPLETE_LOGOUT, 0, CMessageSS.ENCODING_UTF32, "");
                CMessagePack<CMessageSS> okLogoutMsgPack = new CMessagePack<CMessageSS>(okLogoutMsg, index);
                CData.server.Send(okLogoutMsgPack);
            }
            else
            {
                CMessageSS notLoggedInMsg = new CMessageSS(CConst.SERVER_MESSAGE_CLIENT_NOT_LOGGED_IN, 0, CMessageSS.ENCODING_UTF32, "");
                CMessagePack<CMessageSS> notLoggedInMsgPack = new CMessagePack<CMessageSS>(notLoggedInMsg, index);
                CData.server.Send(notLoggedInMsgPack);
            }
        }
    }
}
